package com.example.kaogong.sys.controller;


import com.example.kaogong.common.exception.ParamsErrorException;
import com.example.kaogong.common.utils.Assert;
import com.example.kaogong.common.utils.RespBean;
import com.example.kaogong.sys.pojo.dto.CourseTypeDto;
import com.example.kaogong.sys.pojo.vo.CourseTypeVo;
import com.example.kaogong.sys.service.ICourseTypeService;
import com.google.gson.Gson;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 课程类型 前端控制器
 * </p>
 *
 * @author    
 * @since 2022-03-26
 */
@RestController
@RequestMapping("/course-type")
@Api(tags = "课程类型管理接口")
@Slf4j
public class CourseTypeController {

    @Autowired
    private ICourseTypeService courseTypeService;

    @GetMapping(value = "/manage/courseType")
    @ApiOperation(value = "获取所有课程类型")
    public RespBean<List<CourseTypeVo>> getAllCourseType() {
        RespBean<List<CourseTypeVo>> respBean = courseTypeService.getAllCourseType();
        log.info("response:{}", new Gson().toJson(respBean));
        return respBean;
    }

    @PostMapping(value = "/manage/courseType")
    @ApiOperation(value = "新增课程类型")
    public RespBean addCourseType(@Valid @RequestBody CourseTypeDto courseTypeDto) {
        log.info("request:{}", new Gson().toJson(courseTypeDto));
        RespBean respBean = courseTypeService.addCourseType(courseTypeDto);
        log.info("response:{}", new Gson().toJson(respBean));
        return respBean;
    }

    @DeleteMapping(value = "/manage/courseType/{typeId}")
    @ApiOperation(value = "根据课程类型编号删除课程类型")
    public RespBean deleteCourseTypeByTypeId(@PathVariable Integer typeId) {
        Assert.notNull(typeId, new ParamsErrorException("课程类型编号不能为空"));
        log.info("typeId:{}", typeId);
        RespBean respBean = courseTypeService.deleteCourseTypeByTypeId(typeId);
        log.info("response:{}", new Gson().toJson(respBean));
        return respBean;
    }
}
